package com.zxu.test.util;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class AcUtils {

    /**
     * app内部跳转
     * @param context
     * @param activity
     * @param msg
     */
    public static void launchActivity(Context context, Class<? extends Activity> activity, IntentMsg msg) {
        if (context == null) {
            return;
        }
        Intent intent = new Intent(context, activity);

        if (msg != null) {
            intent.putExtra(IntentMsg.MSG, msg);
        }
        context.startActivity(intent);
    }

    /**
     * 外部跳转
     * @param context
     * @param activity
     * @param msg
     */
    public static void launchOtherActivity(Context context, String pacageName, Class<? extends Activity> activity , IntentMsg msg) {
        if (context == null) {
            return;
        }
        Intent intent = new Intent();
        intent.setClassName(pacageName,activity.getName());
        intent.setComponent(new ComponentName(pacageName,activity.getName()));
        if(intent.resolveActivity(context.getPackageManager()) != null){
            context.startActivity(intent);
        }
    }

    /**
     * 通过隐式跳转
     * @param
     */
    public static void launchActionActivity(Context context, String action, IntentMsg msg) {
        if (context == null) {
            return;
        }
        Intent intent = new Intent(action);
        if (msg != null) {
            intent.putExtra(IntentMsg.MSG, msg);
        }
        //避免出现ActivityNotFoundException
        if(intent.resolveActivity(context.getPackageManager()) != null){
            context.startActivity(intent);
        }
    }
}
